﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Web;
using System.Web.Services;

namespace DeliveryService
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {
        /// <summary>
        /// 餐馆登陆
        /// </summary>
        /// <param name="restaurantId">餐馆</param>
        /// <param name="password">密码（暂用明文，未加密的密码）</param>
        /// <returns>是否登陆成功 true:登陆成功  false：登陆失败</returns>
        [WebMethod]
        public bool RestaurantLogin(int restaurantId, string password)
        {
            BLRestaurant br = new BLRestaurant();
            return br.RestaurantLogin(restaurantId, password);
        }

        /// <summary>
        /// 修改餐馆状态
        /// </summary>
        /// <param name="restaurantId">餐馆ID</param>
        /// <param name="haveList">是否有订单</param>
        /// <returns>true:修改状态成功  false:修改失败</returns>
        [WebMethod]
        public bool ChangeStatus(int restaurantId, bool haveList)
        {
            BLRestaurant br = new BLRestaurant();
            return br.ChangeStatus(restaurantId, haveList);
        }

        /// <summary>
        /// 修改餐馆的忙碌状态
        /// </summary>
        /// <param name="restaurantId">餐馆ID</param>
        /// <param name="isBusy">是否忙碌</param>
        /// <returns>s是否修改成功</returns>
        [WebMethod]
        public bool ChangeRestaurantIsBusy(int restaurantId, bool isBusy)
        {
            BLRestaurant br = new BLRestaurant();
            return br.ChangeRestaurantIsBusy(restaurantId, isBusy);
        }

        /// <summary>
        /// 获取所有快递员名单
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        public List<MCourier> GetAllCouriser()
        {
            BLCouriser bc = new BLCouriser();
            return bc.GetAllCouriser();
        }

        /// <summary>
        /// 根据快递员姓名获取他所管辖的是否有单列为“有”的餐馆
        /// 按下单时间正序
        /// </summary>
        /// <param name="couriserName">快递员姓名</param>
        /// <returns>有订单的餐饮列表</returns>
        [WebMethod]
        public List<MRestaurant> GetRestaurantsWhichHasListsByCouriserName(string couriserName)
        {
            BLRestaurant br = new BLRestaurant();
            return br.GetRestaurants(couriserName);
        }

        /// <summary>
        /// 获取所有的是否有单列为“有”的餐馆
        /// 按下单时间正序
        /// </summary>
        /// <returns>有订单的餐饮列表</returns>
        [WebMethod]
        public List<MRestaurant> GetRestaurantsWhichHasLists()
        {
            BLRestaurant br = new BLRestaurant();
            return br.GetRestaurants();
        }

        /// <summary>
        /// 获取所有学校列表
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        public List<MSchool> GetAllSchool()
        {
            BLSchool bl = new BLSchool();
            return bl.GetSchools();
        }

        /// <summary>
        /// 学生注册
        /// </summary>
        /// <param name="name">学生姓名</param>
        /// <param name="studentsNo">学号</param>
        /// <param name="phone">电话</param>
        /// <param name="branchSchoolId">学校ID</param>
        /// <param name="password">密码</param>
        /// <returns>       
        /// -1:未知错误
        /// 0:注册成功
        /// 1:此学生已存在于学生表中，不可重复注册
        /// 2:学号和姓名不匹配
        /// 3:数据库中不存在此学生的真实信息
        /// 4:此学生信息已被注册过，不能再注册
        /// 5:手机号已被注册
        /// </returns>
        [WebMethod]
        public int Register(string name, string studentsNo, string phone, int SchoolId, string password)
        {
            BLStudents bs = new BLStudents();
            return bs.Register(name, studentsNo, phone, SchoolId, password);
        }

        /// <summary>
        /// 不需要学号的注册
        /// </summary>
        /// <param name="name">学生名</param>
        /// <param name="phone">电话号码</param>
        /// <param name="SchoolId">学校ID</param>
        /// <param name="password">密码</param>
        /// <returns>
        /// return 1: 电话号码已注册
        /// return 0：注册成功
        /// return -1： 未知错误
        /// </returns>
        [WebMethod]
        public int RegisterWithoutStudentNo(string name, string phone, int SchoolId, string password)
        {
            BLStudents bs = new BLStudents();
            return bs.RegisterWithoutStudentNo(name, phone, SchoolId, password);
        }

        /// <summary>
        /// 学生用手机号登陆
        /// </summary>
        /// <param name="phone">手机号</param>
        /// <param name="password">密码</param>
        /// <returns>
        /// -1:不存在此手机号的注册信息
        /// -2:密码错误
        /// >0: 登陆成功，返回学生ID
        /// </returns>
        [WebMethod]
        public int StudentLoginByPhone(string phone, string password)
        {
            BLStudents bs = new BLStudents();
            return bs.StudentsLoginByPhone(phone, password);
        }

        /// <summary>
        /// 学生用学号登陆
        /// </summary>
        /// <param name="studentNo">学号</param>
        /// <param name="password">密码</param>
        /// <returns>
        /// -1:用户名错误：不存在此学号的注册信息
        /// -2:密码错误
        /// >0: 登陆成功，返回学生ID
        /// </returns>
        [WebMethod]
        public int StudentLoginByStudentNumber(string studentNo, string password)
        {
            BLStudents bs = new BLStudents();
            return bs.StudentsLogin(studentNo, password);
        }

        /// <summary>
        /// 根据学号和手机号，找回注册密码
        /// </summary>
        /// <param name="studentNo">学号</param>
        /// <param name="phone">手机号</param>
        /// <returns>密码</returns>
        [WebMethod]
        public string GetBackPassword(string studentNo, string phone)
        {
            BLStudents bs = new BLStudents();
            return bs.GetBackPassword(studentNo, phone);
        }

        /// <summary>
        /// 检查学生姓名和学号是否匹配
        /// </summary>
        /// <param name="studentName">学生姓名</param>
        /// <param name="studentNo">学号</param>
        /// <returns>true: 匹配   false: 不匹配</returns>
        [WebMethod]
        public bool IsRealStudents(string studentName, string studentNo)
        {
            BLStudents bs = new BLStudents();
            return bs.IsRealStudents(studentName, studentNo);
        }

        /// <summary>
        /// 根据学号获取学生信息
        /// 数据库中 sex :  -1->保密   0：男  1：女
        /// </summary>
        /// <param name="studentNo"></param>
        /// <returns></returns>
        [WebMethod]
        public MStudent GetStudentByStuNo(string studentNo)
        {
            BLStudents bs = new BLStudents();
            return bs.GetStudentByStuNo(studentNo);
        }

        /// <summary>
        /// 根据手机号获取学生信息
        /// 数据库中 sex :  -1->保密   0：男  1：女
        /// </summary>
        /// <param name="studentNo"></param>
        /// <returns></returns>
        [WebMethod]
        public MStudent GetStudentByPhone(string phone)
        {
            BLStudents bs = new BLStudents();
            return bs.GetStudentByPhone(phone);
        }

        /// <summary>
        /// 根据菜名称查询菜的信息
        /// 模糊查询
        /// </summary>
        /// <param name="foodName"></param>
        /// <returns></returns>
        [WebMethod]
        public List<MFoods> SearchFoodsByFoodName(string foodName)
        {
            BLFood br = new BLFood();
            return br.SearchFoodsByFoodName(foodName);
        }
        /// <summary>
        /// 根据菜品价格获取菜品信息
        /// </summary>
        /// <param name="fromPrice">开始价格</param>
        /// <param name="toPrice">结束价格</param>
        /// <returns>菜品信息</returns>
        [WebMethod]
        public List<MFoods> SearchFoodsByFoodPrice(double fromPrice, double toPrice)
        {
            BLFood br = new BLFood();
            return br.SearchFoodByFoodPrice(fromPrice, toPrice);
        }
        /// <summary>
        /// 根据菜品分类获取菜品信息
        /// 菜品分类分类支持模糊查询
        /// </summary>
        /// <param name="categoryName">菜品分类</param>
        /// <returns></returns>
        [WebMethod]
        public List<MFoods> SearchFoodsByFoodCategory(string categoryName)
        {
            BLFood br = new BLFood();
            return br.SearchFoodsByFoodCategory(categoryName);
        }
        // <summary>
        /// 根据餐馆和菜品类别获取菜品列表
        /// 餐馆名称和菜品类别支持模糊查询
        /// </summary>
        /// <param name="restaurantName">餐馆名称</param>
        /// <param name="categoryName">菜品类别</param>
        /// <returns></returns>
        [WebMethod]
        public List<MFoods> SearchFoodsByRestaurantAndFoodCategory(string restaurantName, string categoryName)
        {
            BLFood br = new BLFood();
            return br.SearchFoodsByRestaurantAndFoodCategory(restaurantName, categoryName);
        }
        /// <summary>
        /// 根据餐饮名称获取餐馆菜品分类列表
        /// 餐馆名称支持模糊查询
        /// </summary>
        /// <param name="restaurantName"> 餐馆名称</param>
        /// <returns></returns>
        [WebMethod]
        public List<MFoodsCategory> SearchFoodsCategoryByRestaurantName(string restaurantName)
        {
            BLFood br = new BLFood();
            return br.SearchFoodsCategoryByRestaurantName(restaurantName);
        }
        /// <summary>
        /// 获取所有广告,按ID倒序
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        public List<MAdvertising> GetAllAdvertising()
        {
            BLAdvertising br = new BLAdvertising();
            return br.GetAllAdvertising();
        }

        /// <summary>
        /// 获取商品大的分类
        /// </summary>
        /// <returns>商品大的分类</returns>
        [WebMethod]
        public List<MGoodsCategorys> GetGoodsCategorys()
        {
            BLGoodsCategory br = new BLGoodsCategory();
            return br.GetGoodsCategorys();
        }
        /// <summary>
        /// 通过大的商品分类获取小的分类
        /// 支持模糊查询
        /// </summary>
        /// <param name="parentCategoryName">大的商品分类名称</param>
        /// <returns>商品小的分类</returns>
        [WebMethod]
        public List<MGoodsSmallCategorys> GetGoodsSmallCategorysByParentCategoryName(string parentCategoryName)
        {
            BLGoodsSmallCategorys br = new BLGoodsSmallCategorys();
            return br.GetGoodsSmallCategorysByParentCategoryName(parentCategoryName);
        }
        /// <summary>
        /// 通过品牌和小分类获取商品信息
        /// 商品品牌和分类名称支持模糊查询,返回结果按价格正序
        /// </summary>
        /// <param name="brandName">商品品牌</param>
        /// <param name="smallCategory">商品小分类</param>
        /// <returns></returns>
        [WebMethod]
        public List<MGoods> GetGoodsByBrandAndSmallCategory(string brandName, string smallCategory)
        {
            BLGoods br = new BLGoods();
            return br.GetGoodsByBrandAndSmallCategory(brandName, smallCategory);
        }
        /// <summary>
        /// 通过小的商品分类获取品牌分类
        /// 支持模糊查询
        /// </summary>
        /// <param name="goodsSmallCategoryName">小的商品分类名称</param>
        /// <returns></returns>
        [WebMethod]
        public List<MBrands> GetBrandsByGoodsSmallCategoryName(string goodsSmallCategoryName)
        {
            BLBrands br = new BLBrands();
            return br.GetBrandsByGoodsSmallCategoryName(goodsSmallCategoryName);
        }

        /// <summary>
        /// 修改学生密码
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <param name="oldPassword">原密码</param>
        /// <param name="newPassword">新密码</param>
        /// <returns> 1:修改成功  2:原密码错误  3:新密码为空 </returns>
        [WebMethod]
        public int ChangeStudentPassword(int studentId, string oldPassword, string newPassword)
        {
            BLStudents bs = new BLStudents();
            return bs.ChangeStudentPassword(studentId, oldPassword, newPassword);
        }
        /// <summary>
        /// 获取所有餐饮列表
        /// </summary>
        /// <returns>餐饮列表</returns>
        [WebMethod]
        public List<MRestaurant> GetAllRestaurant()
        {
            BLRestaurant br = new BLRestaurant();
            return br.GetAllRestaurants();
        }
        /// <summary>
        /// 获取菜品类别
        /// </summary>
        /// <returns>菜品类别</returns>
        [WebMethod]
        public List<MFoodsCategory> GetAllFoodCategorys()
        {
            BLFoodsCategory br = new BLFoodsCategory();
            return br.GetAllFoodCategorys();
        }
        /// <summary>
        /// 随机获取一种菜的信息,用于手机"摇一摇"
        /// </summary>
        /// <param name="getCount">要返回的菜品数量</param>
        /// <returns>菜的列表</returns>
        [WebMethod]
        public List<MFoods> GetRandomFoods(int getCount)
        {
            BLFood br = new BLFood();
            return br.GetRandomFoods(getCount);
        }
        // <summary>
        /// 添加商品到用户的购物车
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <param name="goodsId">商品ID</param>
        /// <param name="goodsAmount">商品数量</param>
        /// <returns>true:添加成功  false:添加失败</returns>
        [WebMethod]
        public bool AddGoodsToShoppingCart(int studentId, int goodsId, int goodsAmount)
        {
            BLShoppingCart br = new BLShoppingCart();
            return br.AddGoodsToShoppingCart(studentId, goodsId, goodsAmount);
        }

        /// 根据学生ID获取购物车列表
        /// </summary>
        /// <param name="studentId">学员ID</param>
        /// <returns>购物车列表</returns>
        [WebMethod]
        public List<MShoppingCart> GetShoppingCartByStudentId(int studentId)
        {
            BLShoppingCart br = new BLShoppingCart();
            return br.GetShoppingCartByStudentId(studentId);
        }

        /// <summary>
        /// 添加收货地址
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <param name="address">地址信息</param>
        /// <param name="isDefault">是否是默认收货地址.  true:是  false:不是</param>
        /// <returns>如果添加失败你就返回0，成功就返回ID</returns>
        [WebMethod]
        public int AddAddress(int studentId, string address, bool isDefault, string recipient, string phoneNum)
        {
            BLAddress ba = new BLAddress();
            try
            {
                return ba.AddAddress(studentId, address, isDefault, recipient, phoneNum);
            }
            catch (Exception e)
            {
                return 0;
            }
        }
        /// <summary>
        /// 获取学生的所有收货地址
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <returns></returns>
        [WebMethod]
        public List<MAddress> GetStudentAllAddress(int studentId)
        {
            BLAddress ba = new BLAddress();
            return ba.GetStudentAllAddress(studentId);
        }

        /// <summary>
        /// 获取学生的默认收货地址.
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <returns></returns>
        [WebMethod]
        public MAddress GetDefaultAddress(int studentId)
        {
            BLAddress ba = new BLAddress();
            return ba.GetDefaultAddress(studentId);
        }

        /// <summary>
        /// 修改学生的收货地址信息.
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <param name="addressId">地址ID</param>
        /// <param name="addressInfor">地址信息</param>
        /// <param name="isDefault">是否是默认收货地址.  true:是  false:不是</param>
        /// <returns>true:更新成功  false:更新失败</returns>
        [WebMethod]
        public bool UpdateAddress(int studentId, int addressId, string addressInfor, bool isDefault, string recipient, string phoneNum)
        {
            BLAddress ba = new BLAddress();
            return ba.UpdateAddress(studentId, addressId, addressInfor, isDefault, recipient, phoneNum);
        }

        /// <summary>
        /// 删除收货地址.
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <param name="addressId">地址ID</param>
        /// <returns>true:删除成功  false:删除失败</returns>
        [WebMethod]
        public bool DeleteAddress(int studentId, int addressId)
        {
            BLAddress ba = new BLAddress();
            return ba.DeleteAddress(studentId, addressId);
        }

        /// <summary>
        /// 根据商品ID获取商品详细信息
        /// </summary>
        /// <param name="goodsId">商品ID</param>
        /// <returns>商品信息</returns>
        [WebMethod]
        public MGoods GetGoodsInforByGoodsId(int goodsId)
        {
            BLGoods bg = new BLGoods();
            return bg.GetGoodsInforByGoodsId(goodsId);
        }

        /// <summary>
        /// 根据商品小分类名称获取全部商品信息
        /// </summary>
        /// <param name="smallCategoryName">商品小分类名称</param>
        /// <returns>商品信息</returns>
        [WebMethod]
        public List<MGoods> GetGoodsInforBySmallCategoryName(string smallCategoryName)
        {
            BLGoods bg = new BLGoods();
            return bg.GetGoodsInforBySmallCategoryName(smallCategoryName);
        }

        /// <summary>
        /// 添加商品到收藏夹
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <param name="goodsId">商品ID</param>
        /// <returns>0:添加成功  1:添加失败  2:已经收藏过了</returns>
        [WebMethod]
        public int AddGoodsToFavorite(int studentId, int goodsId)
        {
            BLFavorite bf = new BLFavorite();
            return bf.AddGoodsToFavorite(studentId, goodsId);
        }

        /// <summary>
        /// 添加菜品到收藏夹
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <param name="FoodsId">菜品ID</param>
        /// <returns>0:添加成功  1:添加失败  2:已经收藏过了</returns>
        [WebMethod]
        public int AddFoodsToFavorite(int studentId, int FoodsId)
        {
            BLFavorite bf = new BLFavorite();
            return bf.AddFoodsToFavorite(studentId, FoodsId);
        }
        /// <summary>
        /// 获取学生收藏的菜品列表
        /// </summary>
        /// <param name="studentId"></param>
        /// <returns></returns>
        [WebMethod]
        public List<MFavoriteFoods> GetStudentsFavoriteFoods(int studentId)
        {
            BLFavorite bf = new BLFavorite();
            return bf.GetStudentsFavoriteFoods(studentId);
        }
        /// <summary>
        /// 获取学生收藏的商品列表
        /// </summary>
        /// <param name="studentId"></param>
        /// <returns></returns>
        [WebMethod]
        public List<MFavoriteGoods> GetStudentsFavoriteGoods(int studentId)
        {
            BLFavorite bf = new BLFavorite();
            return bf.GetStudentsFavoriteGoods(studentId);
        }
        /// <summary>
        /// 删除收藏的商品
        /// </summary>
        /// <param name="studentId"></param>
        /// <param name="goodsIdList">商品ID,以逗号分隔</param>
        /// <returns></returns>
        [WebMethod]
        public bool DeleteFavoriteGoods(int studentId, string goodsIdList)
        {
            BLFavorite bf = new BLFavorite();
            return bf.DeleteFavoriteGoods(studentId, goodsIdList);
        }

        /// <summary>
        /// 删除收藏的菜品
        /// </summary>
        /// <param name="studentId"></param>
        /// <param name="foodsIdList">菜品ID,以逗号分隔</param>
        /// <returns></returns>
        [WebMethod]
        public bool DeleteFavoriteFoods(int studentId, string foodsIdList)
        {
            BLFavorite bf = new BLFavorite();
            return bf.DeleteFavoriteFoods(studentId, foodsIdList);
        }

        /// <summary>
        ///  删除商品购物车
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <param name="goodsId">商品ID</param>
        /// <returns></returns>
        [WebMethod]
        public bool DeleteGoodsFromShoppingCart(int studentId, int goodsId)
        {
            BLShoppingCart bs = new BLShoppingCart();
            return bs.DeleteGoodsFromShoppingCart(studentId, goodsId);
        }

        /// <summary>
        /// 批量删除商品购物车
        /// </summary> 
        /// <param name="shoppingCartIdList">商品购物车ID列表,以逗号分隔</param>
        /// <returns></returns>
        [WebMethod]
        public bool DeleteGoodsListFromShoppingCart(string shoppingCartIdList)
        {
            BLShoppingCart bs = new BLShoppingCart();
            return bs.DeleteGoodsListFromShoppingCart(shoppingCartIdList);
        }

        /// <summary>
        /// 修改商品购车的数量
        /// </summary>
        /// <param name="shoppingCartId">购物车id</param>
        /// <param name="ammount">数量</param>
        /// <returns></returns>
        [WebMethod]
        public bool EditShoppingCart(int shoppingCartId, int ammount)
        {
            BLShoppingCart bs = new BLShoppingCart();
            return bs.EditShoppingCart(shoppingCartId, ammount);
        }

        /// <summary>
        /// 添加菜品到购物车
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <param name="foodsId">菜品ID</param>
        /// <param name="foodsAmount">菜品数量</param>
        /// <returns></returns>
        [WebMethod]
        public bool AddFoodsToShoppingCart(int studentId, int foodsId, int foodsAmount)
        {
            BLShoppingCartFoods bs = new BLShoppingCartFoods();
            return bs.AddFoodsToShoppingCart(studentId, foodsId, foodsAmount);
        }
        /// <summary>
        /// 根据学生ID获取菜品购物车列表
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <returns></returns>
        [WebMethod]
        public List<MShoppingCartFoods> GetShoppingCartFoodsByStudentId(int studentId)
        {
            BLShoppingCartFoods bs = new BLShoppingCartFoods();
            return bs.GetShoppingCartFoodsByStudentId(studentId);
        }

        /// <summary>
        /// 删除菜品购物车
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <param name="foodsId">菜品ID</param>
        /// <returns></returns>
        [WebMethod]
        public bool DeleteFoodsFromShoppingCart(int studentId, int foodsId)
        {
            BLShoppingCartFoods bs = new BLShoppingCartFoods();
            return bs.DeleteFoodsFromShoppingCart(studentId, foodsId);
        }
        /// <summary>
        /// 批量删除菜品购物车
        /// </summary> 
        /// <param name="shopingCartIdList">菜品购物车ID,以逗号分隔</param>
        /// <returns></returns>
        [WebMethod]
        public bool DeleteFoodsListFromShoppingCart(string shopingCartIdList)
        {
            BLShoppingCartFoods bs = new BLShoppingCartFoods();
            return bs.DeleteFoodsListFromShoppingCart(shopingCartIdList);
        }

        /// <summary>
        /// 修改菜品购物车信息
        /// </summary>
        /// <param name="shoppingCartFoodsId">菜品购物车ID</param>
        /// <param name="ammount">数量</param>
        /// <returns></returns>
        [WebMethod]
        public bool EditShoppingCartFoods(int shoppingCartFoodsId, int ammount)
        {
            BLShoppingCartFoods bs = new BLShoppingCartFoods();
            return bs.EditShoppingCartFoods(shoppingCartFoodsId, ammount);
        }
        /// <summary>
        /// 通过商品名称模糊搜索商品
        /// </summary>
        /// <param name="goodsName"></param>
        /// <returns></returns>
        [WebMethod]
        public List<MGoods> SearchGoodsByName(string goodsName)
        {
            BLGoods bg = new BLGoods();
            return bg.SearchGoodsByName(goodsName);
        }

        /// <summary>
        /// 通过餐馆名称模糊搜索餐馆
        /// </summary>
        /// <param name="restaurantName"></param>
        /// <returns></returns>
        [WebMethod]
        public List<MRestaurant> SerachRestaurantByName(string restaurantName)
        {
            BLRestaurant br = new BLRestaurant();
            return br.SerachRestaurantByName(restaurantName);
        }

        /// <summary>
        /// 根据菜品ID获取菜品信息
        /// </summary>
        /// <param name="foodId">菜品ID</param>
        /// <returns></returns>
        [WebMethod]
        public MFoods SearchFoodsByFoodId(int foodId)
        {
            BLFood bf = new BLFood();
            return bf.SearchFoodsByFoodId(foodId);
        }

        /// <summary>
        /// 提交新的菜品订单
        /// OrderForm
        /// OrderForm_History
        /// OrderForm_Maker 需要一默认员工 : admin
        /// OrderForm_Foods
        /// </summary>
        /// <param name="studentId">学生id</param>
        /// <param name="addressId">地址id</param>
        /// <param name="TotalAmount">菜品总金额</param>
        /// <param name="privilegeAmount">优惠金额</param>
        /// <param name="payableAmount">应付金额</param>
        /// <param name="comment">备注</param>
        /// <param name="foodsIdAndAmount">菜品id和对应的数量,需要按照以下格式传输,如:
        /// [{"Id":1,"Amount":2},{"Id":2,"Amount":1},{"Id":3,"Amount":3},{"Id":4,"Amount":4}]</param>
        /// <returns>订单ID</returns>
        [WebMethod]
        public string AddNewFoodsOrderForm(int studentId, int addressId, double TotalAmount, double privilegeAmount,
                                    double payableAmount, string comment, string foodsIdAndAmount)
        {
            BLFoodsOrder bf = new BLFoodsOrder();
            return bf.AddNewFoodsOrder(studentId, addressId, TotalAmount, privilegeAmount, payableAmount, comment, foodsIdAndAmount);
        }

        /// <summary>
        /// 更改订单状态
        /// </summary>
        /// <param name="OrderFormId">订单ID</param>
        /// <param name="status">0: 待发货, 1: 已发货  2:已收货  3:已取消</param>
        /// <param name="staffId">操作订单的员工ID</param>
        /// <param name="comment">备注/param>
        /// <returns></returns>
        [WebMethod]
        public bool ChangeOrderFormStatus(int OrderFormId, int status, int staffId, string comment)
        {
            BLOrder bf = new BLOrder();
            return bf.ChangeOrderFormStatus(OrderFormId, status, staffId, comment);
        }

        /// <summary>
        /// 获取所有餐饮列表
        /// </summary>
        /// <returns>餐饮列表</returns>
        [WebMethod]
        public string GetAllRestaurantList()
        {
            BLRestaurant br = new BLRestaurant();
            return br.GetAllRestaurantList();
        }

        /// <summary>
        /// 提交新的商品订单
        /// OrderForm
        /// OrderForm_History
        /// OrderForm_Maker 需要一默认员工 : admin
        /// OrderForm_Goods
        /// </summary>
        /// <param name="studentId">学生id</param>
        /// <param name="addressId">地址id</param>
        /// <param name="TotalAmount">商品总金额</param>
        /// <param name="privilegeAmount">优惠金额</param>
        /// <param name="payableAmount">应付金额</param>
        /// <param name="comment">备注</param>
        /// <param name="goodsIdAndAmount">商品id和对应的数量,需要按照以下格式传输,如:
        /// [{"Id":1,"Amount":2},{"Id":2,"Amount":1},{"Id":3,"Amount":3}]</param>
        /// <returns>订单ID</returns>
        [WebMethod]
        public string AddNewGoodsOrderForm(int studentId, int addressId, double TotalAmount, double privilegeAmount,
                                    double payableAmount, string comment, string goodsIdAndAmount)
        {
            BLGoodsOrder bg = new BLGoodsOrder();
            return bg.AddNewGoodsOrderForm(studentId, addressId, TotalAmount, privilegeAmount, payableAmount, comment, goodsIdAndAmount);
        }

        /// <summary>
        /// 根据学生姓名获取此学生的菜品订单
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <returns>菜品订单详情</returns>
        [WebMethod]
        public string GetFoodsOrderFormsByStudentId(int studentId)
        {
            BLFoodsOrder bf = new BLFoodsOrder();
            return bf.GetFoodsOrderFormsByStudentId(studentId);
        }

        /// <summary>
        /// 根据学生姓名获取此学生的商品品订单
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <returns>商品订单详情</returns>
        [WebMethod]
        public string GetGoodsOrderFormsByStudentId(int studentId)
        {
            BLGoodsOrder bg = new BLGoodsOrder();
            return bg.GetGoodsOrderFormsByStudentId(studentId);
        }

        /// <summary>
        /// 根据学生ID和订单状态查询商品品订单
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <param name="orderStatus">订单状态</param>
        /// <returns>商品订单列表</returns>
        [WebMethod]
        public string GetGoodsOrderFormsByStatues(int studentId, int orderStatus)
        {
            BLGoodsOrder bg = new BLGoodsOrder();
            return bg.GetGoodsOrderFormsByStatues(studentId, orderStatus);
        }

        /// <summary>
        /// 根据学生ID和订单状态查询菜品订单
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <param name="orderStatus">订单状态</param>
        /// <returns>菜品订单详情</returns>
        [WebMethod]
        public string GetFoodsOrderFormsByStatues(int studentId, int orderStatus)
        {
            BLFoodsOrder bf = new BLFoodsOrder();
            return bf.GetFoodsOrderFormsByStatues(studentId, orderStatus);
        }

        /// <summary>
        /// 根据订单号获取该订单对应的商品对象和商品数量
        /// </summary>
        /// <param name="orderFormNumber">订单号</param>
        /// <returns>商品订单详情</returns>
        [WebMethod]
        public string GetGoodsOrderFormsByOrderFormNumber(string orderFormNumber)
        {
            BLGoodsOrder bg = new BLGoodsOrder();
            return bg.GetGoodsOrderFormsByOrderFormNumber(orderFormNumber);
        }

        /// <summary>
        /// 根据订单号获取该订单对应的菜品对象和商品数量
        /// </summary>
        /// <param name="orderFormNumber">订单号</param>
        /// <returns>菜品订单详情</returns>
        [WebMethod]
        public string GetFoodsOrderFormsByOrderFormNumber(string orderFormNumber)
        {
            BLFoodsOrder bf = new BLFoodsOrder();
            return bf.GetFoodsOrderFormsByOrderFormNumber(orderFormNumber);
        }

        /// <summary>
        /// 提交新的菜品/商品订单 
        /// </summary>
        /// <param name="studentId">学生id</param>
        /// <param name="addressId">地址id</param>
        /// <param name="TotalAmount">商品总金额</param>
        /// <param name="privilegeAmount">优惠金额</param>
        /// <param name="payableAmount">应付金额</param>
        /// <param name="comment">备注</param>
        /// <param name="foodsIdAndAmount">菜品id和对应的数量,需要按照以下格式传输,如:
        /// [{"Id":1,"Amount":2},{"Id":2,"Amount":1},{"Id":3,"Amount":3}]</param>
        /// <param name="goodsIdAndAmount">商品id和对应的数量,需要按照以下格式传输,如:
        /// [{"Id":1,"Amount":2},{"Id":2,"Amount":1},{"Id":3,"Amount":3}]</param>
        /// <returns>订单ID</returns>
        [WebMethod]
        public string AddNewOrder(int studentId, int addressId, double TotalAmount, double privilegeAmount,
                                    double payableAmount, string comment, string foodsIdAndAmount, string goodsIdAndAmount)
        {
            BLOrder bo = new BLOrder();
            return bo.AddNewOrder(studentId, addressId, TotalAmount, privilegeAmount, payableAmount, comment, foodsIdAndAmount, goodsIdAndAmount);
        }


        /// <summary>
        /// 根据学生姓名获取此学生的订单列表
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <returns>订单详情</returns>
        [WebMethod]
        public string GetOrderFormsByStudentId(int studentId)
        {
            BLOrder bo = new BLOrder();
            return bo.GetOrderFormsByStudentId(studentId);
        }
        /// <summary>
        /// 根据学生ID和订单状态查询订单
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <param name="orderStatus">订单状态</param>
        /// <returns>订单详情</returns>
        [WebMethod]
        public string GetOrderFormsByStatues(int studentId, int orderStatus)
        {
            BLOrder bo = new BLOrder();
            return bo.GetOrderFormsByStatues(studentId, orderStatus);
        }

        /// <summary>
        /// 根据订单号获取该订单对应的菜品对象和商品数量
        /// </summary>
        /// <param name="orderFormNumber">订单号</param>
        /// <returns>菜品订单详情</returns>
        [WebMethod]
        public string GetOrderFormsByOrderFormNumber(string orderFormNumber)
        {
            BLOrder bo = new BLOrder();
            return bo.GetOrderFormsByOrderFormNumber(orderFormNumber);
        }

        /// <summary>
        /// 根据学生ID获取所有的购物车以及购物车内所有物品
        /// </summary>
        /// <param name="StudentI">学生id</param>
        /// <returns></returns>
        [WebMethod]
        public string GetAllThingsFromStudentId(int StudentI)
        {
            BLAllThings allth = new BLAllThings();
            return allth.GetAllThingsFromStudentId(StudentI);
        }

        /// <summary>
        /// 根据订单状态查询订单,并返回详情。此接口仅供电脑服务端使用
        /// </summary>
        /// <param name="status">订单状态</param>
        /// <returns>订单列表</returns>
        [WebMethod]
        public string GetOrderFormsDetailsByStatues(int status)
        {
            BLOrder orders = new BLOrder();
            return orders.GetOrderFormsDetailsByStatues(status);
        }


        /// <summary>
        /// 根据下单时间查询订单,并返回详情。此接口仅供电脑服务端使用
        /// </summary>
        /// <param name="QureyDateTime">下单时间</param>
        /// <returns>订单列表</returns> 
        [WebMethod]
        public string GetOrderFormsDetailsByData(DateTime QureyDateTime)
        {
            BLOrder orders = new BLOrder();
            return orders.GetOrderFormsDetailsByData(QureyDateTime);
        }

        /// <summary>
        /// 按时间段查询订单
        /// </summary>
        /// <param name="FromTime">开始时间</param>
        /// <param name="ToTime">结束时间</param>
        /// <returns>该时间段内的订单详情</returns>
        [WebMethod]
        public string GetOrderFormsDetailsByDurationTime(DateTime FromTime, DateTime ToTime)
        {
            BLOrder orders = new BLOrder();
            return orders.GetOrderFormsDetailsByDurationTime(FromTime, ToTime);
        }

        /// <summary>
        /// 根据下单时间和订单状态查询订单,并返回详情。此接口仅供电脑服务端使用
        /// </summary>
        /// <param name="QureyDateTime">下单时间</param>
        /// <param name="orderStatus">订单状态</param>
        /// <returns>订单列表</returns> 
        [WebMethod]
        public string GetOrderFormsDetailsByDataAndStatues(DateTime QureyDateTime, int orderStatus)
        {
            BLOrder orders = new BLOrder();
            return orders.GetOrderFormsDetailsByDataAndStatues(QureyDateTime, orderStatus);
        }

        /// <summary>
        /// 查询某一天有多少个订单
        /// </summary>
        /// <param name="queryDate"></param>
        /// <returns></returns>
        [WebMethod]
        public int GetOrdersCountByDate(DateTime queryDate)
        {
            BLOrder orders = new BLOrder();
            return orders.GetOrdersCountByDate(queryDate);
        }

        /// <summary>
        /// 查询某一天第一个订单号
        /// </summary>
        /// <param name="queryDate"></param>
        /// <returns></returns>
        [WebMethod]
        public int GetOneDaysFirstOrderId(DateTime queryDate)
        {
            BLOrder orders = new BLOrder();
            return orders.GetOneDaysFirstOrderId(queryDate);
        }


        [DllImport("EUCPComm.dll", EntryPoint = "SendSMS")]  //即时发送
        public static extern int SendSMS(string sn, string mn, string ct, string priority);

        [WebMethod]
        public int SendSMS(string PhoneNum, string Code)
        {
            BLStudents bSt = new BLStudents();
            if (bSt.IsPhoneExisits(PhoneNum))
            {
                return 0;
            }

            string mess = "您好，你的验证码为:" + Code + "。如非本人操作，请忽略此信息【小甲虫软件科技有限公司】";
            //                        软件序列号        手机号  短信内容  优先级
            int result = SendSMS("3SDK-EMY-0130-PJUOP", PhoneNum, mess, "0");
            return result;
        }

        // 获取所有学生的列表，需要特定的用户名和密码验证
        [WebMethod]
        public string GetAllStudents(string phone, string password)
        {
            BLStudents bSt = new BLStudents();
            return bSt.GetAllStudents(phone, password);
        }
    }
}